let aa = {
	computed: {
		$banner() {
			return [{
					image: 'https://cdn.uviewui.com/uview/swiper/1.jpg',
					title: '昨夜',
					price: 26,
					id: 1
				},
				{
					image: 'https://cdn.uviewui.com/uview/swiper/2.jpg',
					title: '身无彩凤双飞翼，心有灵犀一点通',
					price: 999.99,
					id: 2
				},
				{
					image: 'https://cdn.uviewui.com/uview/swiper/3.jpg',
					title: '谁念西风独自凉，萧萧黄叶闭疏窗，沉思往事立残阳',
					price: 59.1,
					id: 3
				}
			]
		},
		$baseUrl() {
			return this.$global.baseUrl
		},
		$zs() {
			return '#00BEC3'
		},
		$fs() {
			return '#FD4834'
		},
		$userInfo() {
			return this.$store.state.userInfo
		},
		$user() {
			return this.$store.state.userInfo
		},
		$config() {
			return this.$store.state.config
		},
	},
	data() {
		return {
			page: 1, //页面的分页
			$params: '', //页面参数
			shareData: { //小程序分享参数
				title: '',
				imageUrl: '',
				path: '',
			},

		}
	},
	onLoad(e) { //页面打开
		this.$params = e
		// this.shareData = {
		// 	title: '',
		// 	imageUrl: '',
		// 	path: '',
		// }
		if (e.shopToken) {
			this.$setCache('shopToken', e.shopToken)
			this.$getConfig()
		}
		if (e.tit) {
			uni.setNavigationBarTitle({
				title: e.tit
			})
		}
		/* 判断是不是带邀请码 */
		if (e.regcode) uni.setStorageSync('regcode', e.regcode)
		/* 扫小程序码的参数  只有邀请码 */
		if (e.scene) uni.setStorageSync('regcode', e.scene)
	},
	//页面显示
	onShow(e) {
		/* 用于h5是 无 title 时 展示链接问题 */
		// #ifdef H5
		let navTitle = document.getElementsByTagName('title')[0];
		if (!navTitle.innerText) navTitle.innerText = this.$u.sys().appName
		// #endif
	},
	//页面加载完成
	onReady() {
		// this.$refs?.uForm?.setRules(this.$rules);
	},
	onShareAppMessage() {
		this.shareData.title=this.shareData.title||this.$config?.shop_title||''
		let pages = getCurrentPages()
		let page = pages[pages.length - 1]
		let path = decodeURI(page.$page.fullPath)
		path.indexOf('?') == -1 ? path += '?' : path += '&'
		this.shareData.path = `${path}regcode=${this.$user.regcode}`
		return this.shareData
	},
	// #ifdef MP-WEIXIN
	onShareTimeline() {
		this.shareData.title=this.shareData.title||this.$config?.shop_title||''
		this.shareData.query = `regcode=${this.$user.regcode}`
		return this.shareData
	},
	// #endif
	onPullDownRefresh() {
		this.$refresh().then(res => {
			this.$nextTick().then(res => {
				uni.showToast({
					title: '刷新成功',
					icon: "none"
				})
				uni.stopPullDownRefresh()
			})
		})
	},
	methods: {
		$getUser() { //用户信息接口
			return new Promise((resolve, reject) => {
				this.$request('/member/my/info').then(res => {
					let data = res.data
					this.$store.commit('setUser', data) //存到vuex
				});
			})
		},
		$getConfig() { //全局基本配置信息接口
			return new Promise((resolve, reject) => {
				let params = {
					city_id: this.$getCache('myAdd')?.id || "",
				}
				this.$request('/master/commom/config', params).then(res => {
					let data = res.data
					this.$store.commit('setConfig', data) //存到vuex
					// if (!params.city_id) {
					// 	this.$setCache('myAdd', {
					// 		id: data.city_id,
					// 		name: data.city_name
					// 	})
					// }

					uni.$emit('config', data)
					uni.$emit('socketurl', data.socketurl)
					resolve(data)
				})
			})
		},
		$login_success(res) { //登录成功
			this.$msg(res.msg)

			if (res.data.type == 1) {
				this.$u.route('/pages/public/bindMobile', res.data)
				return
			}

			uni.removeStorageSync('regcode') //清除邀请码
			this.$store.commit('setToken', res.data.token.access_token) //存到vuex
			this.$getUser()
			this.$store.dispatch('chat/start');

			setTimeout(() => { //跳转
				// #ifndef MP-WEIXIN
				this.$navBack() //返回
				// #endif
				this.$nextTick().then(res => {
					setTimeout(this.$refresh, 100)
				})
			}, 800)
		},
		$logOut() { //退出登录
			let that = this
			uni.showModal({
				title: "退出登录",
				content: '确认要退出登录吗？',
				success: (res) => {
					if (res.confirm) {
						that.$msg('退出成功')
						uni.removeStorageSync('token')
						that.$store.commit('setUser', {}) //存到vuex
						that.$store.dispatch('chat/close');
						setTimeout(() => {
							that.$tool.rjump('/pages/public/login')
						}, 1000)
						that.$store.dispatch('chat/close');
						console.log('退出登录');
					} else {
						console.log('取消');
					}
				}
			})
		},

		$advJumpList(list, index) { //轮播图跳转
			this.$advJump(list[index || 0])
		},
		$advJump(data) { //单图跳转
			if (data?.url?.substr(0, 4) == 'http') {
				this.$tool.openLink(data.url)
			} else {
				this.$u.route(data.url, data.params)
				this.$u.route({
					url: data.url,
					type: 'tab'
				})
			}
			let obj = {
				url: '/pages/integral/task',
				params: {
					id: 1,
					type: 'goods'
				}
			}
		},
		get_add_list() {
			this.addList = getApp()?.globalData?.addList || uni.getStorageSync('addList') || []
			this.$request('/api/wanlshop.common/area').then(res => {
				this.addList = res.data
				getApp().globalData.addList = res.data
				uni.setStorageSync('addList', res.data)
			})
		},

	}
}
export default aa
